import java.rmi.RemoteException;
import java.sql.SQLException;
import java.util.Calendar;

import IOHelper.DataBaseHelper;
import StructureBL.StructureController;



public class ServerManageController extends DataBaseHelper
{
	public ServerManageController()
	{
		super();
	}
	public boolean delTrash() throws RemoteException
	{
		boolean result = false;
		StructureController sc = new StructureController();
		Calendar c = Calendar.getInstance();
		String now = new String();
		now+=c.get(c.YEAR);
		if(c.get(c.MONTH)+1<10)
		{
			now+="0"+c.get(c.MONTH);
		}else
		{
			now+=c.get(c.MONTH);
		}
		if(c.get(c.DATE)+1<10)
		{
			now+="0"+c.get(c.DATE);
		}else
		{
			now+=c.get(c.DATE);
		}
		if(Integer.valueOf(now)<Integer.valueOf(sc.getStructure().selectLessonEnd))
		{
			return false;
		}
		
		String studentaim=(c.get(c.YEAR))-7+"";
		connect();
		String delLesson = "DELETE * FROM Lesson";
		String delPlan="DELETE * FROM Plan";
		String delSelectLesson="DELETE * FROM SelectLesson";
		String delStudent="DELETE * FROM Student WHERE CINT(enterYear) <="+studentaim;
		System.out.println(studentaim);
		try
		{
			stmt = con.prepareStatement(delLesson);
			stmt.execute();
			stmt = con.prepareStatement(delPlan);
			stmt.execute();
			stmt = con.prepareStatement(delSelectLesson);
			stmt.execute();
			stmt = con.prepareStatement(delStudent);
			stmt.execute();
			con.commit();
			result = true;
		} catch (SQLException e)
		{
			e.printStackTrace();
			result = false;
		} finally
		{
			reset();
			return result;
		}
	}
}
